<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="../../template/tagedu.xhtml">

    <ui:define name="title">
        <title><h:outputText value="TAG - Notas e Frequência"/></title>  
        <f:metadata>
            <f:viewParam name="organization" value="#{performanceFrequency.orgFatherID}"/>
        </f:metadata>
    </ui:define>
    <ui:define name="content">
        <link rel="Stylesheet" type="text/css" href="../../resources/css/performance.css"></link>
        <h:outputText styleClass="title" value="Notas e Frequências"/>
        <h:form styleClass="body" id="performanceForm">
            <p:message id="messages" for="searchGrid"/>
            <h:panelGrid columns="1" id="searchGrid">
                <h:panelGroup id="organizations">
                    <h:outputLabel for="organization" value="Organização:"/>
                    <p:selectOneMenu id="organization" value="#{performanceFrequency.organizationID}" style="width: 400px">
                        <f:selectItems value="#{performanceFrequency.organizationList}"/>
                        <p:ajax process="@this" update="years unities disciplines plans actorsTable"
                                listener="#{performanceFrequency.loadYearList()}"/>
                    </p:selectOneMenu>
                </h:panelGroup>
                <h:panelGroup id="years">
                    <h:outputLabel for="year" value="Ano:"/>
                    <p:selectOneMenu id="year" value="#{performanceFrequency.year}" style="width: 400px">
                        <f:selectItems value="#{performanceFrequency.yearList}"/>
                        <p:ajax process="@this" update="unities disciplines plans actorsTable" 
                                listener="#{performanceFrequency.loadUnityList()}"/>
                    </p:selectOneMenu>
                </h:panelGroup>                
                <h:panelGroup id="unities">
                    <h:outputLabel for="unity" value="Unidade:"/>
                    <p:selectOneMenu id="unity" value="#{performanceFrequency.unityID}" style="width: 400px">
                        <f:selectItems value="#{performanceFrequency.unityList}"/>
                        <p:ajax process="@this" update="disciplines plans actorsTable" 
                                listener="#{performanceFrequency.loadDisciplineList()}"/>
                    </p:selectOneMenu>
                </h:panelGroup>                
                <h:panelGroup id="disciplines">
                    <h:outputLabel for="discipline" value="Disciplina:"/>
                    <p:selectOneMenu id="discipline" value="#{performanceFrequency.disciplineID}" style="width: 400px">
                        <f:selectItems value="#{performanceFrequency.disciplineList}"/>
                        <p:ajax process="@this" update="plans actorsTable" 
                                listener="#{performanceFrequency.loadPlanList()}"/>
                    </p:selectOneMenu>
                </h:panelGroup>
                <h:panelGroup id="plans">
                    <h:outputLabel for="plan" value="Plano:"/>
                    <p:selectOneMenu id="plan" value="#{performanceFrequency.planID}" style="width: 400px">
                        <f:selectItems value="#{performanceFrequency.planList}"/>
                        <p:ajax process="@this" update="actorsTable" 
                                listener="#{performanceFrequency.generatePerformanceList}"/>
                    </p:selectOneMenu>
                </h:panelGroup>
            </h:panelGrid> 

            <br/><br/>

            <h:panelGrid id="actorsTable">
                <p:dataTable rendered="#{not empty performanceFrequency.performanceFrequencyList}" 
                             value="#{performanceFrequency.performanceFrequencyList}" var="performance">
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Nome"/>
                        </f:facet>
                        <h:outputText value="#{sessionBean.findHumanName(performance.actor.person.id)}"/>
                    </p:column>
                    <p:column headerText="Notas">
                        <p:inputText validatorMessage="Deve ser número entre 0.00 e 10.00" 
                                     id="inputGrade" value="#{performance.grade}" 
                                     style="width: 60px" required="true" 
                                     requiredMessage="Campo Obrigatório"/>
                        <h:message showSummary="true" showDetail="false" style="color: red" for="inputGrade"/>
                    </p:column>
                    <p:column headerText="Frequência">                       
                        <p:inputText validatorMessage="Deve ser número entre 0.00 e 100.00" 
                                     id="inputFrequency" value="#{performance.frequency}" 
                                     style="width: 100px" required="true" 
                                     requiredMessage="Campo Obrigatório"/>
                        <h:message showSummary="true" showDetail="false" style="color: red" for="inputFrequency"/>
                    </p:column>
                </p:dataTable>
                <p:commandButton id="editGradesButton" rendered="#{not empty performanceFrequency.performanceFrequencyList}" 
                                 value="Confirmar" ajax="true" process="@this actorsTable" update="messages actorsTable"
                                 action="#{performanceFrequency.savePerformances}">
                </p:commandButton>
            </h:panelGrid>
        </h:form>
    </ui:define>
    
    <ui:define name="modals"></ui:define>
    
</ui:composition>
